home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
listings
/
v_11_07
/
1107123a
< prev
next >
Wrap
Text File
|
1993-05-05
|
602b
|
41 lines
//
// list.cpp - list implementation using a nested class
// with global variables counting the objects
//
#include <stdio.h>
#include "list.h"
unsigned list_count = 0;
list::list(unsigned n)
{
first = last = new node (n, 0);
++list_count;
}
list::~list()
{
node *p;
while ((p = first) != 0)
{
first = first->next;
delete p;
}
--list_count;
}
void list::add(unsigned n)
{
if (last->number != n)
last = last->next = new node (n, 0);
}
void list::print()
{
for (node *p = first; p != 0; p = p->next)
printf("%4u ", p->number);
}